CXX = g++
OBJECTS = CTCPPort.o CUDPPort.o BitStream.o main.o common.o
LIBS = -lrt
INCLUDES = -I ./extensions/ -I ./include/
MAJOR = 0
MINOR = 4
BUILD = 2
VERSION = $(MAJOR).$(MINOR).$(BUILD)
NAME = libOpenNetwork.so

ifdef DEBUG
CFLAGS = -Wall -O2 -shared -fPIC -g
BINDIR = $(DESTDIR)/usr/debug/lib
else	
CFLAGS = -Wall -O2 -shared -fPIC
BINDIR = $(DESTDIR)/usr/lib
endif
	
all: $(NAME)
.PHONY: all
	
$(NAME): $(OBJECTS)
	$(CXX) -o $(NAME).$(VERSION) $(CFLAGS) $(OBJECTS) $(LIBS) $(INCLUDES)


CTCPPort.o: CTCPPort.cpp CTCPPort.h
	$(CXX) -c CTCPPort.cpp $(CFLAGS) $(INCLUDES)

main.o: main.cpp
	$(CXX) -c main.cpp $(CFLAGS) $(INCLUDES)

CUDPPort.o: CUDPPort.cpp CUDPPort.h
	$(CXX) -c CUDPPort.cpp $(CFLAGS) $(INCLUDES)

common.o: common.cpp common.h
	$(CXX) -c common.cpp $(CFLAGS) $(INCLUDES)

BitStream.o : ./extensions/BitStream/BitStream.cpp ./extensions/BitStream/BitStream.h
	$(CXX) -c ./extensions/BitStream/BitStream.cpp $(CFLAGS) $(INCLUDES)


install:
	cp -s -f $(NAME).$(VERSION) $(NAME)
	cp -s -f $(NAME).$(VERSION) $(NAME).$(MAJOR)

	install --mode=755 $(NAME).$(VERSION) $(BINDIR)/ 
	install --mode=755 $(NAME)            $(BINDIR)/$(NAME)
	install --mode=755 $(NAME).$(MAJOR)   $(BINDIR)/$(NAME).$(MAJOR)

clean:
	rm -f *.o

uninstall:
	rm $(BINDIR)/$(NAME).$(VERSION)
	rm $(BINDIR)/$(NAME).$(MAJOR).$(MINOR)
	rm $(BINDIR)/$(NAME).$(MAJOR)
